3 * User interface for page actions.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * Class for viewing MediaWiki article and history.
26 * This maintains WikiPage functions for backwards compatibility.
28 * @todo move and rewrite code to an Action class
30 * See design.txt for an overview.
31 * Note: edit user interface and cache support functions have been
32 * moved to separate EditPage and HTMLFileCache classes.
34 * @internal documentation reviewed 15 Mar 2010
36 class Article
extends Page
{
42 * The context this Article is executed in
43 * @var IContextSource $mContext
48 * The WikiPage object of this instance
49 * @var WikiPage $mPage
54 * ParserOptions object for $wgUser articles
55 * @var ParserOptions $mParserOptions
57 public $mParserOptions;
60 * Text of the revision we are working on
61 * @var string $mContent
63 var $mContent; // !< #BC cruft
66 * Content of the revision we are working on
70 var $mContentObject; // !<
73 * Is the content ($mContent) already loaded?
74 * @var bool $mContentLoaded
76 var $mContentLoaded = false; // !<
79 * The oldid of the article that is to be shown, 0 for the
81 * @var int|null $mOldId
86 * Title from which we were redirected here
87 * @var Title $mRedirectedFrom
89 var $mRedirectedFrom = null;
92 * URL to redirect to or false if none
93 * @var string|false $mRedirectUrl
95 var $mRedirectUrl = false; // !<
98 * Revision ID of revision we are working on
99 * @var int $mRevIdFetched
101 var $mRevIdFetched = 0; // !<
104 * Revision we are working on
105 * @var Revision $mRevision
107 var $mRevision = null;
110 * ParserOutput object
111 * @var ParserOutput $mParserOutput
118 * Constructor and clear the article
119 * @param $title Title Reference to a Title object.
120 * @param $oldId Integer revision ID, null to fetch from request, zero for current
122 public function __construct( Title
$title, $oldId = null ) {
123 $this->mOldId
= $oldId;
124 $this->mPage
= $this->newPage( $title );
128 * @param $title Title
131 protected function newPage( Title
$title ) {
132 return new WikiPage( $title );
136 * Constructor from a page id
137 * @param $id Int article ID to load
138 * @return Article|null
140 public static function newFromID( $id ) {
141 $t = Title
::newFromID( $id );
142 # @todo FIXME: Doesn't inherit right
143 return $t == null ?
null : new self( $t );
144 # return $t == null ? null : new static( $t ); // PHP 5.3
148 * Create an Article object of the appropriate class for the given page.
150 * @param $title Title
151 * @param $context IContextSource
152 * @return Article object
154 public static function newFromTitle( $title, IContextSource
$context ) {
155 if ( NS_MEDIA
== $title->getNamespace() ) {
156 // FIXME: where should this go?
157 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
161 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
163 switch( $title->getNamespace() ) {
165 $page = new ImagePage( $title );
168 $page = new CategoryPage( $title );
171 $page = new Article( $title );
174 $page->setContext( $context );
180 * Create an Article object of the appropriate class for the given page.
182 * @param $page WikiPage
183 * @param $context IContextSource
184 * @return Article object
186 public static function newFromWikiPage( WikiPage
$page, IContextSource
$context ) {
187 $article = self
::newFromTitle( $page->getTitle(), $context );
188 $article->mPage
= $page; // override to keep process cached vars
193 * Tell the page view functions that this view was redirected
194 * from another page on the wiki.
195 * @param $from Title object.
197 public function setRedirectedFrom( Title
$from ) {
198 $this->mRedirectedFrom
= $from;
202 * Get the title object of the article
204 * @return Title object of this page
206 public function getTitle() {
207 return $this->mPage
->getTitle();
211 * Get the WikiPage object of this instance
216 public function getPage() {
223 public function clear() {
224 $this->mContentLoaded
= false;
226 $this->mRedirectedFrom
= null; # Title object if set
227 $this->mRevIdFetched
= 0;
228 $this->mRedirectUrl
= false;
230 $this->mPage
->clear();
234 * Note that getContent/loadContent do not follow redirects anymore.
235 * If you need to fetch redirectable content easily, try
236 * the shortcut in WikiPage::getRedirectTarget()
238 * This function has side effects! Do not use this function if you
239 * only want the real revision text if any.
241 * @deprecated in 1.WD; use getContentObject() instead
243 * @return string Return the text of this revision
245 public function getContent() {
246 wfDeprecated( __METHOD__
, '1.WD' );
247 $content = $this->getContentObject();
248 return ContentHandler
::getContentText( $content );
252 * Returns a Content object representing the pages effective display content,
253 * not necessarily the revision's content!
255 * Note that getContent/loadContent do not follow redirects anymore.
256 * If you need to fetch redirectable content easily, try
257 * the shortcut in WikiPage::getRedirectTarget()
259 * This function has side effects! Do not use this function if you
260 * only want the real revision text if any.
262 * @return Content Return the content of this revision
266 protected function getContentObject() {
268 wfProfileIn( __METHOD__
);
270 if ( $this->mPage
->getID() === 0 ) {
271 # If this is a MediaWiki:x message, then load the messages
272 # and return the message value for x.
273 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
274 $text = $this->getTitle()->getDefaultMessageText();
275 if ( $text === false ) {
279 $content = ContentHandler
::makeContent( $text, $this->getTitle() );
281 $content = new MessageContent( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon', null, 'parsemag' );
283 wfProfileOut( __METHOD__
);
287 $this->fetchContentObject();
288 wfProfileOut( __METHOD__
);
290 return $this->mContentObject
;
295 * @return int The oldid of the article that is to be shown, 0 for the
298 public function getOldID() {
299 if ( is_null( $this->mOldId
) ) {
300 $this->mOldId
= $this->getOldIDFromRequest();
303 return $this->mOldId
;
307 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
309 * @return int The old id for the request
311 public function getOldIDFromRequest() {
312 $this->mRedirectUrl
= false;
314 $request = $this->getContext()->getRequest();
315 $oldid = $request->getIntOrNull( 'oldid' );
317 if ( $oldid === null ) {
321 if ( $oldid !== 0 ) {
322 # Load the given revision and check whether the page is another one.
323 # In that case, update this instance to reflect the change.
324 if ( $oldid === $this->mPage
->getLatest() ) {
325 $this->mRevision
= $this->mPage
->getRevision();
327 $this->mRevision
= Revision
::newFromId( $oldid );
328 if ( $this->mRevision
!== null ) {
329 // Revision title doesn't match the page title given?
330 if ( $this->mPage
->getID() != $this->mRevision
->getPage() ) {
331 $function = array( get_class( $this->mPage
), 'newFromID' );
332 $this->mPage
= call_user_func( $function, $this->mRevision
->getPage() );
338 if ( $request->getVal( 'direction' ) == 'next' ) {
339 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
342 $this->mRevision
= null;
344 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
346 } elseif ( $request->getVal( 'direction' ) == 'prev' ) {
347 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
350 $this->mRevision
= null;
358 * Load the revision (including text) into this object
360 * @deprecated in 1.19; use fetchContent()
362 function loadContent() {
363 wfDeprecated( __METHOD__
, '1.19' );
364 $this->fetchContent();
368 * Get text of an article from database
369 * Does *NOT* follow redirects.
372 * @note this is really internal functionality that should really NOT be used by other functions. For accessing
373 * article content, use the WikiPage class, especially WikiBase::getContent(). However, a lot of legacy code
374 * uses this method to retrieve page text from the database, so the function has to remain public for now.
376 * @return mixed string containing article contents, or false if null
377 * @deprecated in 1.WD, use WikiPage::getContent() instead
379 function fetchContent() { #BC cruft!
380 wfDeprecated( __METHOD__
, '1.WD' );
382 if ( $this->mContentLoaded
&& $this->mContent
) {
383 return $this->mContent
;
386 wfProfileIn( __METHOD__
);
388 $content = $this->fetchContentObject();
390 $this->mContent
= ContentHandler
::getContentText( $content ); #@todo: get rid of mContent everywhere!
391 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) ); #BC cruft! #XXX: can we deprecate that hook?
393 wfProfileOut( __METHOD__
);
395 return $this->mContent
;
400 * Get text content object
401 * Does *NOT* follow redirects.
402 * TODO: when is this null?
404 * @note code that wants to retrieve page content from the database should use WikiPage::getContent().
406 * @return Content|null
410 protected function fetchContentObject() {
411 if ( $this->mContentLoaded
) {
412 return $this->mContentObject
;
415 wfProfileIn( __METHOD__
);
417 $this->mContentLoaded
= true;
418 $this->mContent
= null;
420 $oldid = $this->getOldID();
422 # Pre-fill content with error message so that if something
423 # fails we'll have something telling us what we intended.
424 $t = $this->getTitle()->getPrefixedText();
425 $d = $oldid ?
wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
426 $this->mContentObject
= new MessageContent( 'missing-article', array($t, $d), array() ) ; // @todo: this isn't page content but a UI message. horrible.
429 # $this->mRevision might already be fetched by getOldIDFromRequest()
430 if ( !$this->mRevision
) {
431 $this->mRevision
= Revision
::newFromId( $oldid );
432 if ( !$this->mRevision
) {
433 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
434 wfProfileOut( __METHOD__
);
439 if ( !$this->mPage
->getLatest() ) {
440 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
441 wfProfileOut( __METHOD__
);
445 $this->mRevision
= $this->mPage
->getRevision();
447 if ( !$this->mRevision
) {
448 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
449 wfProfileOut( __METHOD__
);
454 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
455 // We should instead work with the Revision object when we need it...
456 $this->mContentObject
= $this->mRevision
->getContent( Revision
::FOR_THIS_USER
); // Loads if user is allowed
457 $this->mRevIdFetched
= $this->mRevision
->getId();
459 wfRunHooks( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject
) );
461 wfProfileOut( __METHOD__
);
463 return $this->mContentObject
;
468 * @deprecated since 1.18
470 public function forUpdate() {
471 wfDeprecated( __METHOD__
, '1.18' );
475 * Returns true if the currently-referenced revision is the current edit
476 * to this page (and it exists).
479 public function isCurrent() {
480 # If no oldid, this is the current version.
481 if ( $this->getOldID() == 0 ) {
485 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
489 * Get the fetched Revision object depending on request parameters or null
493 * @return Revision|null
495 public function getRevisionFetched() {
496 $this->fetchContentObject();
498 return $this->mRevision
;
502 * Use this to fetch the rev ID used on page views
504 * @return int revision ID of last article revision
506 public function getRevIdFetched() {
507 if ( $this->mRevIdFetched
) {
508 return $this->mRevIdFetched
;
510 return $this->mPage
->getLatest();
515 * This is the default action of the index.php entry point: just view the
516 * page of the given title.
518 public function view() {
519 global $wgParser, $wgUseFileCache, $wgUseETag, $wgDebugToolbar;
521 wfProfileIn( __METHOD__
);
523 # Get variables from query string
524 # As side effect this will load the revision and update the title
525 # in a revision ID is passed in the request, so this should remain
526 # the first call of this method even if $oldid is used way below.
527 $oldid = $this->getOldID();
529 $user = $this->getContext()->getUser();
530 # Another whitelist check in case getOldID() is altering the title
531 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
532 if ( count( $permErrors ) ) {
533 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
534 wfProfileOut( __METHOD__
);
535 throw new PermissionsError( 'read', $permErrors );
538 $outputPage = $this->getContext()->getOutput();
539 # getOldID() may as well want us to redirect somewhere else
540 if ( $this->mRedirectUrl
) {
541 $outputPage->redirect( $this->mRedirectUrl
);
542 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
543 wfProfileOut( __METHOD__
);
548 # If we got diff in the query, we want to see a diff page instead of the article.
549 if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
550 wfDebug( __METHOD__
. ": showing diff page\n" );
551 $this->showDiffPage();
552 wfProfileOut( __METHOD__
);
557 # Set page title (may be overridden by DISPLAYTITLE)
558 $outputPage->setPageTitle( $this->getTitle()->getPrefixedText() );
560 $outputPage->setArticleFlag( true );
561 # Allow frames by default
562 $outputPage->allowClickjacking();
564 $parserCache = ParserCache
::singleton();
566 $parserOptions = $this->getParserOptions();
567 # Render printable version, use printable version cache
568 if ( $outputPage->isPrintable() ) {
569 $parserOptions->setIsPrintable( true );
570 $parserOptions->setEditSection( false );
571 } elseif ( !$this->isCurrent() ||
!$this->getTitle()->quickUserCan( 'edit' ) ) {
572 $parserOptions->setEditSection( false );
575 # Try client and file cache
576 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
578 $outputPage->setETag( $parserCache->getETag( $this, $parserOptions ) );
581 # Is it client cached?
582 if ( $outputPage->checkLastModified( $this->mPage
->getTouched() ) ) {
583 wfDebug( __METHOD__
. ": done 304\n" );
584 wfProfileOut( __METHOD__
);
588 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
589 wfDebug( __METHOD__
. ": done file cache\n" );
590 # tell wgOut that output is taken care of
591 $outputPage->disable();
592 $this->mPage
->doViewUpdates( $user );
593 wfProfileOut( __METHOD__
);
599 # Should the parser cache be used?
600 $useParserCache = $this->mPage
->isParserCacheUsed( $parserOptions, $oldid );
601 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
602 if ( $user->getStubThreshold() ) {
603 wfIncrStats( 'pcache_miss_stub' );
606 $this->showRedirectedFromHeader();
607 $this->showNamespaceHeader();
609 # Iterate through the possible ways of constructing the output text.
610 # Keep going until $outputDone is set, or we run out of things to do.
613 $this->mParserOutput
= false;
615 while ( !$outputDone && ++
$pass ) {
618 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
621 # Early abort if the page doesn't exist
622 if ( !$this->mPage
->exists() ) {
623 wfDebug( __METHOD__
. ": showing missing article\n" );
624 $this->showMissingArticle();
625 wfProfileOut( __METHOD__
);
629 # Try the parser cache
630 if ( $useParserCache ) {
631 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
633 if ( $this->mParserOutput
!== false ) {
635 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
636 $this->setOldSubtitle( $oldid );
638 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
640 $outputPage->addParserOutput( $this->mParserOutput
);
641 # Ensure that UI elements requiring revision ID have
642 # the correct version information.
643 $outputPage->setRevisionId( $this->mPage
->getLatest() );
644 # Preload timestamp to avoid a DB hit
645 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
646 if ( $cachedTimestamp !== null ) {
647 $outputPage->setRevisionTimestamp( $cachedTimestamp );
648 $this->mPage
->setTimestamp( $cachedTimestamp );
655 # This will set $this->mRevision if needed
656 $this->fetchContentObject();
658 # Are we looking at an old revision
659 if ( $oldid && $this->mRevision
) {
660 $this->setOldSubtitle( $oldid );
662 if ( !$this->showDeletedRevisionHeader() ) {
663 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
664 wfProfileOut( __METHOD__
);
669 # Ensure that UI elements requiring revision ID have
670 # the correct version information.
671 $outputPage->setRevisionId( $this->getRevIdFetched() );
672 # Preload timestamp to avoid a DB hit
673 $outputPage->setRevisionTimestamp( $this->getTimestamp() );
675 # Pages containing custom CSS or JavaScript get special treatment
676 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
677 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
678 $this->showCssOrJsPage();
680 } elseif( !wfRunHooks( 'ArticleContentViewCustom', array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
681 # Allow extensions do their own custom view for certain pages
683 } elseif( Hooks
::isRegistered( 'ArticleViewCustom' ) && !wfRunHooks( 'ArticleViewCustom', array( $this->fetchContent(), $this->getTitle(), $outputPage ) ) ) { #FIXME: fetchContent() is deprecated!
684 # Allow extensions do their own custom view for certain pages
687 $content = $this->getContentObject();
688 $rt = $content->getRedirectChain();
690 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
691 # Viewing a redirect page (e.g. with parameter redirect=no)
692 $outputPage->addHTML( $this->viewRedirect( $rt ) );
693 # Parse just to get categories, displaytitle, etc.
694 $this->mParserOutput
= $content->getParserOutput( $this->getTitle(), $oldid, $parserOptions, false );
695 $outputPage->addParserOutputNoText( $this->mParserOutput
);
701 # Run the parse, protected by a pool counter
702 wfDebug( __METHOD__
. ": doing uncached parse\n" );
704 // @todo: shouldn't we be passing $this->getPage() to PoolWorkArticleView instead of plain $this?
705 $poolArticleView = new PoolWorkArticleView( $this, $parserOptions,
706 $this->getRevIdFetched(), $useParserCache, $this->getContentObject(), $this->getContext() );
708 if ( !$poolArticleView->execute() ) {
709 $error = $poolArticleView->getError();
711 $outputPage->clearHTML(); // for release() errors
712 $outputPage->enableClientCache( false );
713 $outputPage->setRobotPolicy( 'noindex,nofollow' );
715 $errortext = $error->getWikiText( false, 'view-pool-error' );
716 $outputPage->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
718 # Connection or timeout error
719 wfProfileOut( __METHOD__
);
723 $this->mParserOutput
= $poolArticleView->getParserOutput();
724 $outputPage->addParserOutput( $this->mParserOutput
);
726 # Don't cache a dirty ParserOutput object
727 if ( $poolArticleView->getIsDirty() ) {
728 $outputPage->setSquidMaxage( 0 );
729 $outputPage->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
734 # Should be unreachable, but just in case...
740 # Get the ParserOutput actually *displayed* here.
741 # Note that $this->mParserOutput is the *current* version output.
742 $pOutput = ( $outputDone instanceof ParserOutput
)
743 ?
$outputDone // object fetched by hook
744 : $this->mParserOutput
;
746 # Adjust title for main page & pages with displaytitle
748 $this->adjustDisplayTitle( $pOutput );
751 # For the main page, overwrite the <title> element with the con-
752 # tents of 'pagetitle-view-mainpage' instead of the default (if
754 # This message always exists because it is in the i18n files
755 if ( $this->getTitle()->isMainPage() ) {
756 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
757 if ( !$msg->isDisabled() ) {
758 $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
762 # Check for any __NOINDEX__ tags on the page using $pOutput
763 $policy = $this->getRobotPolicy( 'view', $pOutput );
764 $outputPage->setIndexPolicy( $policy['index'] );
765 $outputPage->setFollowPolicy( $policy['follow'] );
767 $this->showViewFooter();
768 $this->mPage
->doViewUpdates( $user );
770 wfProfileOut( __METHOD__
);
774 * Adjust title for pages with displaytitle, -{T|}- or language conversion
775 * @param $pOutput ParserOutput
777 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
778 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
779 $titleText = $pOutput->getTitleText();
780 if ( strval( $titleText ) !== '' ) {
781 $this->getContext()->getOutput()->setPageTitle( $titleText );
786 * Show a diff page according to current request variables. For use within
787 * Article::view() only, other callers should use the DifferenceEngine class.
789 public function showDiffPage() {
790 $request = $this->getContext()->getRequest();
791 $user = $this->getContext()->getUser();
792 $diff = $request->getVal( 'diff' );
793 $rcid = $request->getVal( 'rcid' );
794 $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) );
795 $purge = $request->getVal( 'action' ) == 'purge';
796 $unhide = $request->getInt( 'unhide' ) == 1;
797 $oldid = $this->getOldID();
799 $contentHandler = ContentHandler
::getForTitle( $this->getTitle() );
800 $de = $contentHandler->createDifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
802 // DifferenceEngine directly fetched the revision:
803 $this->mRevIdFetched
= $de->mNewid
;
804 $de->showDiffPage( $diffOnly );
806 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
807 # Run view updates for current revision only
808 $this->mPage
->doViewUpdates( $user );
813 * Show a page view for a page formatted as CSS or JavaScript. To be called by
814 * Article::view() only.
816 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
819 protected function showCssOrJsPage( $showCacheHint = true ) {
822 if ( $showCacheHint ) {
823 $dir = $this->getContext()->getLanguage()->getDir();
824 $lang = $this->getContext()->getLanguage()->getCode();
826 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
830 // Give hooks a chance to customise the output
831 if ( !Hooks
::isRegistered('ShowRawCssJs') ||
wfRunHooks( 'ShowRawCssJs', array( $this->fetchContent(), $this->getTitle(), $wgOut ) ) ) { #FIXME: fetchContent() is deprecated
832 $po = $this->mContentObject
->getParserOutput( $this->getTitle() );
833 $wgOut->addHTML( $po->getText() );
838 * Get the robot policy to be used for the current view
839 * @param $action String the action= GET parameter
840 * @param $pOutput ParserOutput
841 * @return Array the policy that should be set
842 * TODO: actions other than 'view'
844 public function getRobotPolicy( $action, $pOutput ) {
845 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
847 $ns = $this->getTitle()->getNamespace();
849 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
850 # Don't index user and user talk pages for blocked users (bug 11443)
851 if ( !$this->getTitle()->isSubpage() ) {
852 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
854 'index' => 'noindex',
855 'follow' => 'nofollow'
861 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
862 # Non-articles (special pages etc), and old revisions
864 'index' => 'noindex',
865 'follow' => 'nofollow'
867 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
868 # Discourage indexing of printable versions, but encourage following
870 'index' => 'noindex',
873 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
874 # For ?curid=x urls, disallow indexing
876 'index' => 'noindex',
881 # Otherwise, construct the policy based on the various config variables.
882 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
884 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
885 # Honour customised robot policies for this namespace
886 $policy = array_merge(
888 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
891 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
892 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
893 # a final sanity check that we have really got the parser output.
894 $policy = array_merge(
896 array( 'index' => $pOutput->getIndexPolicy() )
900 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
901 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
902 $policy = array_merge(
904 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
912 * Converts a String robot policy into an associative array, to allow
913 * merging of several policies using array_merge().
914 * @param $policy Mixed, returns empty array on null/false/'', transparent
915 * to already-converted arrays, converts String.
916 * @return Array: 'index' => \<indexpolicy\>, 'follow' => \<followpolicy\>
918 public static function formatRobotPolicy( $policy ) {
919 if ( is_array( $policy ) ) {
921 } elseif ( !$policy ) {
925 $policy = explode( ',', $policy );
926 $policy = array_map( 'trim', $policy );
929 foreach ( $policy as $var ) {
930 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
931 $arr['index'] = $var;
932 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
933 $arr['follow'] = $var;
941 * If this request is a redirect view, send "redirected from" subtitle to
942 * the output. Returns true if the header was needed, false if this is not
943 * a redirect view. Handles both local and remote redirects.
947 public function showRedirectedFromHeader() {
948 global $wgRedirectSources;
949 $outputPage = $this->getContext()->getOutput();
951 $rdfrom = $this->getContext()->getRequest()->getVal( 'rdfrom' );
953 if ( isset( $this->mRedirectedFrom
) ) {
954 // This is an internally redirected page view.
955 // We'll need a backlink to the source page for navigation.
956 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
957 $redir = Linker
::linkKnown(
958 $this->mRedirectedFrom
,
961 array( 'redirect' => 'no' )
964 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
966 // Set the fragment if one was specified in the redirect
967 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
968 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
969 $outputPage->addInlineScript( "redirectToFragment(\"$fragment\");" );
972 // Add a <link rel="canonical"> tag
973 $outputPage->addLink( array( 'rel' => 'canonical',
974 'href' => $this->getTitle()->getLocalURL() )
977 // Tell the output object that the user arrived at this article through a redirect
978 $outputPage->setRedirectedFrom( $this->mRedirectedFrom
);
982 } elseif ( $rdfrom ) {
983 // This is an externally redirected view, from some other wiki.
984 // If it was reported from a trusted site, supply a backlink.
985 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
986 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
987 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
997 * Show a header specific to the namespace currently being viewed, like
998 * [[MediaWiki:Talkpagetext]]. For Article::view().
1000 public function showNamespaceHeader() {
1001 if ( $this->getTitle()->isTalkPage() ) {
1002 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
1003 $this->getContext()->getOutput()->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
1009 * Show the footer section of an ordinary page view
1011 public function showViewFooter() {
1012 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1013 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
1014 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
1017 # If we have been passed an &rcid= parameter, we want to give the user a
1018 # chance to mark this new article as patrolled.
1019 $this->showPatrolFooter();
1021 wfRunHooks( 'ArticleViewFooter', array( $this ) );
1026 * If patrol is possible, output a patrol UI box. This is called from the
1027 * footer section of ordinary page views. If patrol is not possible or not
1028 * desired, does nothing.
1030 public function showPatrolFooter() {
1031 $request = $this->getContext()->getRequest();
1032 $outputPage = $this->getContext()->getOutput();
1033 $user = $this->getContext()->getUser();
1034 $rcid = $request->getVal( 'rcid' );
1036 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
1040 $token = $user->getEditToken( $rcid );
1041 $outputPage->preventClickjacking();
1043 $outputPage->addHTML(
1044 "<div class='patrollink'>" .
1046 'markaspatrolledlink',
1049 wfMsgHtml( 'markaspatrolledtext' ),
1052 'action' => 'markpatrolled',
1056 array( 'known', 'noclasses' )
1064 * Show the error text for a missing article. For articles in the MediaWiki
1065 * namespace, show the default message text. To be called from Article::view().
1067 public function showMissingArticle() {
1068 global $wgSend404Code;
1069 $outputPage = $this->getContext()->getOutput();
1071 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1072 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
1073 $parts = explode( '/', $this->getTitle()->getText() );
1074 $rootPart = $parts[0];
1075 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
1076 $ip = User
::isIP( $rootPart );
1078 if ( !($user && $user->isLoggedIn()) && !$ip ) { # User does not exist
1079 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1080 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
1081 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
1082 LogEventsList
::showLogExtract(
1085 $user->getUserPage()->getPrefixedText(),
1089 'showIfEmpty' => false,
1091 'blocked-notice-logextract',
1092 $user->getName() # Support GENDER in notice
1099 wfRunHooks( 'ShowMissingArticle', array( $this ) );
1101 # Show delete and move logs
1102 LogEventsList
::showLogExtract( $outputPage, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
1104 'conds' => array( "log_action != 'revision'" ),
1105 'showIfEmpty' => false,
1106 'msgKey' => array( 'moveddeleted-notice' ) )
1109 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code ) {
1110 // If there's no backing content, send a 404 Not Found
1111 // for better machine handling of broken links.
1112 $this->getContext()->getRequest()->response()->header( "HTTP/1.1 404 Not Found" );
1115 $hookResult = wfRunHooks( 'BeforeDisplayNoArticleText', array( $this ) );
1117 if ( ! $hookResult ) {
1121 # Show error message
1122 $oldid = $this->getOldID();
1124 $text = wfMsgNoTrans( 'missing-article',
1125 $this->getTitle()->getPrefixedText(),
1126 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
1127 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
1128 // Use the default message text
1129 $text = $this->getTitle()->getDefaultMessageText();
1131 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $this->getContext()->getUser() );
1132 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $this->getContext()->getUser() );
1133 $errors = array_merge( $createErrors, $editErrors );
1135 if ( !count( $errors ) ) {
1136 $text = wfMsgNoTrans( 'noarticletext' );
1138 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
1141 $text = "<div class='noarticletext'>\n$text\n</div>";
1143 $outputPage->addWikiText( $text );
1147 * If the revision requested for view is deleted, check permissions.
1148 * Send either an error message or a warning header to the output.
1150 * @return boolean true if the view is allowed, false if not.
1152 public function showDeletedRevisionHeader() {
1153 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1158 $outputPage = $this->getContext()->getOutput();
1159 // If the user is not allowed to see it...
1160 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1161 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1162 'rev-deleted-text-permission' );
1165 // If the user needs to confirm that they want to see it...
1166 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1167 # Give explanation and add a link to view the revision...
1168 $oldid = intval( $this->getOldID() );
1169 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
1170 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1171 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1172 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1173 array( $msg, $link ) );
1176 // We are allowed to see...
1178 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1179 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1180 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1187 * Generate the navigation links when browsing through an article revisions
1188 * It shows the information as:
1189 * Revision as of \<date\>; view current revision
1190 * \<- Previous version | Next Version -\>
1192 * @param $oldid int: revision ID of this article revision
1194 public function setOldSubtitle( $oldid = 0 ) {
1195 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1199 $unhide = $this->getContext()->getRequest()->getInt( 'unhide' ) == 1;
1201 # Cascade unhide param in links for easy deletion browsing
1202 $extraParams = array();
1204 $extraParams['unhide'] = 1;
1207 if ( $this->mRevision
&& $this->mRevision
->getId() === $oldid ) {
1208 $revision = $this->mRevision
;
1210 $revision = Revision
::newFromId( $oldid );
1213 $timestamp = $revision->getTimestamp();
1215 $current = ( $oldid == $this->mPage
->getLatest() );
1216 $language = $this->getContext()->getLanguage();
1217 $td = $language->timeanddate( $timestamp, true );
1218 $tddate = $language->date( $timestamp, true );
1219 $tdtime = $language->time( $timestamp, true );
1221 # Show user links if allowed to see them. If hidden, then show them only if requested...
1222 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1224 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1225 ?
'revision-info-current'
1228 $outputPage = $this->getContext()->getOutput();
1229 $outputPage->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1230 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1231 $tdtime, $revision->getUser() )->parse() . "</div>" );
1234 ?
wfMsgHtml( 'currentrevisionlink' )
1237 wfMsgHtml( 'currentrevisionlink' ),
1240 array( 'known', 'noclasses' )
1243 ?
wfMsgHtml( 'diff' )
1246 wfMsgHtml( 'diff' ),
1252 array( 'known', 'noclasses' )
1254 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1258 wfMsgHtml( 'previousrevision' ),
1261 'direction' => 'prev',
1264 array( 'known', 'noclasses' )
1266 : wfMsgHtml( 'previousrevision' );
1270 wfMsgHtml( 'diff' ),
1276 array( 'known', 'noclasses' )
1278 : wfMsgHtml( 'diff' );
1279 $nextlink = $current
1280 ?
wfMsgHtml( 'nextrevision' )
1283 wfMsgHtml( 'nextrevision' ),
1286 'direction' => 'next',
1289 array( 'known', 'noclasses' )
1291 $nextdiff = $current
1292 ?
wfMsgHtml( 'diff' )
1295 wfMsgHtml( 'diff' ),
1301 array( 'known', 'noclasses' )
1304 $cdel = Linker
::getRevDeleteLink( $this->getContext()->getUser(), $revision, $this->getTitle() );
1305 if ( $cdel !== '' ) {
1309 $outputPage->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1310 wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1311 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>" );
1317 * @param $target Title|Array of destination(s) to redirect
1318 * @param $appendSubtitle Boolean [optional]
1319 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1320 * @return string containing HMTL with redirect link
1322 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1323 global $wgStylePath;
1325 if ( !is_array( $target ) ) {
1326 $target = array( $target );
1329 $lang = $this->getTitle()->getPageLanguage();
1330 $imageDir = $lang->getDir();
1332 if ( $appendSubtitle ) {
1333 $this->getContext()->getOutput()->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1336 // the loop prepends the arrow image before the link, so the first case needs to be outside
1341 $title = array_shift( $target );
1343 if ( $forceKnown ) {
1344 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1346 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1349 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1350 $alt = $lang->isRTL() ?
'←' : '→';
1351 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1352 foreach ( $target as $rt ) {
1353 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1354 if ( $forceKnown ) {
1355 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1357 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1361 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1362 return '<div class="redirectMsg">' .
1363 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1364 '<span class="redirectText">' . $link . '</span></div>';
1368 * Handle action=render
1370 public function render() {
1371 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1376 * action=protect handler
1378 public function protect() {
1379 $form = new ProtectionForm( $this );
1384 * action=unprotect handler (alias)
1386 public function unprotect() {
1391 * UI entry point for page deletion
1393 public function delete() {
1394 # This code desperately needs to be totally rewritten
1396 $title = $this->getTitle();
1397 $user = $this->getContext()->getUser();
1400 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1401 if ( count( $permission_errors ) ) {
1402 throw new PermissionsError( 'delete', $permission_errors );
1405 # Read-only check...
1406 if ( wfReadOnly() ) {
1407 throw new ReadOnlyError
;
1410 # Better double-check that it hasn't been deleted yet!
1411 $dbw = wfGetDB( DB_MASTER
);
1412 $conds = $title->pageCond();
1413 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1414 if ( $latest === false ) {
1415 $outputPage = $this->getContext()->getOutput();
1416 $outputPage->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1417 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1418 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1420 $outputPage->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1421 LogEventsList
::showLogExtract(
1424 $title->getPrefixedText()
1430 $request = $this->getContext()->getRequest();
1431 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1432 $deleteReason = $request->getText( 'wpReason' );
1434 if ( $deleteReasonList == 'other' ) {
1435 $reason = $deleteReason;
1436 } elseif ( $deleteReason != '' ) {
1437 // Entry from drop down menu + additional comment
1438 $reason = $deleteReasonList . wfMsgForContent( 'colon-separator' ) . $deleteReason;
1440 $reason = $deleteReasonList;
1443 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1444 array( 'delete', $this->getTitle()->getPrefixedText() ) ) )
1446 # Flag to hide all contents of the archived revisions
1447 $suppress = $request->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1449 $this->doDelete( $reason, $suppress );
1451 if ( $request->getCheck( 'wpWatch' ) && $user->isLoggedIn() ) {
1453 } elseif ( $title->userIsWatching() ) {
1460 // Generate deletion reason
1461 $hasHistory = false;
1464 $reason = $this->generateReason( $hasHistory );
1465 } catch (MWException
$e) {
1466 # if a page is horribly broken, we still want to be able to delete it. so be lenient about errors here.
1467 wfDebug("Error while building auto delete summary: $e");
1472 // If the page has a history, insert a warning
1473 if ( $hasHistory ) {
1474 $revisions = $this->mTitle
->estimateRevisionCount();
1475 // @todo FIXME: i18n issue/patchwork message
1476 $this->getContext()->getOutput()->addHTML( '<strong class="mw-delete-warning-revisions">' .
1477 wfMsgExt( 'historywarning', array( 'parseinline' ), $this->getContext()->getLanguage()->formatNum( $revisions ) ) .
1478 wfMsgHtml( 'word-separator' ) . Linker
::link( $title,
1479 wfMsgHtml( 'history' ),
1480 array( 'rel' => 'archives' ),
1481 array( 'action' => 'history' ) ) .
1485 if ( $this->mTitle
->isBigDeletion() ) {
1486 global $wgDeleteRevisionsLimit;
1487 $this->getContext()->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1488 array( 'delete-warning-toobig', $this->getContext()->getLanguage()->formatNum( $wgDeleteRevisionsLimit ) ) );
1492 return $this->confirmDelete( $reason );
1496 * Output deletion confirmation dialog
1497 * @todo FIXME: Move to another file?
1498 * @param $reason String: prefilled reason
1500 public function confirmDelete( $reason ) {
1501 wfDebug( "Article::confirmDelete\n" );
1503 $outputPage = $this->getContext()->getOutput();
1504 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1505 $outputPage->addBacklinkSubtitle( $this->getTitle() );
1506 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1507 $outputPage->addWikiMsg( 'confirmdeletetext' );
1509 wfRunHooks( 'ArticleConfirmDelete', array( $this, $outputPage, &$reason ) );
1511 $user = $this->getContext()->getUser();
1513 if ( $user->isAllowed( 'suppressrevision' ) ) {
1514 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1516 <td class='mw-input'><strong>" .
1517 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1518 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1524 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1526 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1527 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1528 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1529 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1530 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1531 "<tr id=\"wpDeleteReasonListRow\">
1532 <td class='mw-label'>" .
1533 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1535 <td class='mw-input'>" .
1536 Xml
::listDropDown( 'wpDeleteReasonList',
1537 wfMsgForContent( 'deletereason-dropdown' ),
1538 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1541 <tr id=\"wpDeleteReasonRow\">
1542 <td class='mw-label'>" .
1543 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1545 <td class='mw-input'>" .
1546 Html
::input( 'wpReason', $reason, 'text', array(
1548 'maxlength' => '255',
1556 # Disallow watching if user is not logged in
1557 if ( $user->isLoggedIn() ) {
1561 <td class='mw-input'>" .
1562 Xml
::checkLabel( wfMsg( 'watchthis' ),
1563 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1572 <td class='mw-submit'>" .
1573 Xml
::submitButton( wfMsg( 'deletepage' ),
1574 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1577 Xml
::closeElement( 'table' ) .
1578 Xml
::closeElement( 'fieldset' ) .
1579 Html
::hidden( 'wpEditToken', $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
1580 Xml
::closeElement( 'form' );
1582 if ( $user->isAllowed( 'editinterface' ) ) {
1583 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1584 $link = Linker
::link(
1586 wfMsgHtml( 'delete-edit-reasonlist' ),
1588 array( 'action' => 'edit' )
1590 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1593 $outputPage->addHTML( $form );
1594 $outputPage->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1595 LogEventsList
::showLogExtract( $outputPage, 'delete',
1596 $this->getTitle()->getPrefixedText()
1601 * Perform a deletion and output success or failure messages
1603 * @param $suppress bool
1605 public function doDelete( $reason, $suppress = false ) {
1607 $outputPage = $this->getContext()->getOutput();
1608 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, 0, true, $error ) ) {
1609 $deleted = $this->getTitle()->getPrefixedText();
1611 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
1612 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1614 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1616 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1617 $outputPage->returnToMain( false );
1619 $outputPage->setPageTitle( wfMessage( 'cannotdelete-title', $this->getTitle()->getPrefixedText() ) );
1620 if ( $error == '' ) {
1621 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1622 array( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1624 $outputPage->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1626 LogEventsList
::showLogExtract(
1629 $this->getTitle()->getPrefixedText()
1632 $outputPage->addHTML( $error );
1637 /* Caching functions */
1640 * checkLastModified returns true if it has taken care of all
1641 * output to the client that is necessary for this request.
1642 * (that is, it has sent a cached version of the page)
1644 * @return boolean true if cached version send, false otherwise
1646 protected function tryFileCache() {
1647 static $called = false;
1650 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1655 if ( $this->isFileCacheable() ) {
1656 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1657 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1658 wfDebug( "Article::tryFileCache(): about to load file\n" );
1659 $cache->loadFromFileCache( $this->getContext() );
1662 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1663 ob_start( array( &$cache, 'saveToFileCache' ) );
1666 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1673 * Check if the page can be cached
1676 public function isFileCacheable() {
1679 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1680 $cacheable = $this->mPage
->getID()
1681 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1682 // Extension may have reason to disable file caching on some pages.
1684 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1694 * Lightweight method to get the parser output for a page, checking the parser cache
1695 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1696 * consider, so it's not appropriate to use there.
1698 * @since 1.16 (r52326) for LiquidThreads
1700 * @param $oldid mixed integer Revision ID or null
1701 * @param $user User The relevant user
1702 * @return ParserOutput or false if the given revsion ID is not found
1704 public function getParserOutput( $oldid = null, User
$user = null ) {
1705 $user = is_null( $user ) ?
$this->getContext()->getUser() : $user;
1706 $parserOptions = $this->mPage
->makeParserOptions( $user );
1708 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
1712 * Get parser options suitable for rendering the primary article wikitext
1713 * @return ParserOptions
1715 public function getParserOptions() {
1716 if ( !$this->mParserOptions
) {
1717 $this->mParserOptions
= $this->mPage
->makeParserOptions( $this->getContext()->getUser() );
1719 // Clone to allow modifications of the return value without affecting cache
1720 return clone $this->mParserOptions
;
1724 * Sets the context this Article is executed in
1726 * @param $context IContextSource
1729 public function setContext( $context ) {
1730 $this->mContext
= $context;
1734 * Gets the context this Article is executed in
1736 * @return IContextSource
1739 public function getContext() {
1740 if ( $this->mContext
instanceof IContextSource
) {
1741 return $this->mContext
;
1743 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1744 return RequestContext
::getMain();
1749 * Info about this page
1750 * @deprecated since 1.19
1752 public function info() {
1753 wfDeprecated( __METHOD__
, '1.19' );
1754 Action
::factory( 'info', $this )->show();
1758 * Mark this particular edit/page as patrolled
1759 * @deprecated since 1.18
1761 public function markpatrolled() {
1762 wfDeprecated( __METHOD__
, '1.18' );
1763 Action
::factory( 'markpatrolled', $this )->show();
1767 * Handle action=purge
1768 * @deprecated since 1.19
1769 * @return Action|bool|null false if the action is disabled, null if it is not recognised
1771 public function purge() {
1772 return Action
::factory( 'purge', $this )->show();
1776 * Handle action=revert
1777 * @deprecated since 1.19
1779 public function revert() {
1780 wfDeprecated( __METHOD__
, '1.19' );
1781 Action
::factory( 'revert', $this )->show();
1785 * Handle action=rollback
1786 * @deprecated since 1.19
1788 public function rollback() {
1789 wfDeprecated( __METHOD__
, '1.19' );
1790 Action
::factory( 'rollback', $this )->show();
1794 * User-interface handler for the "watch" action.
1795 * Requires Request to pass a token as of 1.18.
1796 * @deprecated since 1.18
1798 public function watch() {
1799 wfDeprecated( __METHOD__
, '1.18' );
1800 Action
::factory( 'watch', $this )->show();
1804 * Add this page to the current user's watchlist
1806 * This is safe to be called multiple times
1808 * @return bool true on successful watch operation
1809 * @deprecated since 1.18
1811 public function doWatch() {
1812 wfDeprecated( __METHOD__
, '1.18' );
1813 return WatchAction
::doWatch( $this->getTitle(), $this->getContext()->getUser() );
1817 * User interface handler for the "unwatch" action.
1818 * Requires Request to pass a token as of 1.18.
1819 * @deprecated since 1.18
1821 public function unwatch() {
1822 wfDeprecated( __METHOD__
, '1.18' );
1823 Action
::factory( 'unwatch', $this )->show();
1827 * Stop watching a page
1828 * @return bool true on successful unwatch
1829 * @deprecated since 1.18
1831 public function doUnwatch() {
1832 wfDeprecated( __METHOD__
, '1.18' );
1833 return WatchAction
::doUnwatch( $this->getTitle(), $this->getContext()->getUser() );
1837 * Output a redirect back to the article.
1838 * This is typically used after an edit.
1840 * @deprecated in 1.18; call OutputPage::redirect() directly
1841 * @param $noRedir Boolean: add redirect=no
1842 * @param $sectionAnchor String: section to redirect to, including "#"
1843 * @param $extraQuery String: extra query params
1845 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1846 wfDeprecated( __METHOD__
, '1.18' );
1848 $query = 'redirect=no';
1850 $query .= "&$extraQuery";
1852 $query = $extraQuery;
1855 $this->getContext()->getOutput()->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1859 * Use PHP's magic __get handler to handle accessing of
1860 * raw WikiPage fields for backwards compatibility.
1862 * @param $fname String Field name
1864 public function __get( $fname ) {
1865 if ( property_exists( $this->mPage
, $fname ) ) {
1866 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1867 return $this->mPage
->$fname;
1869 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1873 * Use PHP's magic __set handler to handle setting of
1874 * raw WikiPage fields for backwards compatibility.
1876 * @param $fname String Field name
1877 * @param $fvalue mixed New value
1879 public function __set( $fname, $fvalue ) {
1880 if ( property_exists( $this->mPage
, $fname ) ) {
1881 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1882 $this->mPage
->$fname = $fvalue;
1883 // Note: extensions may want to toss on new fields
1884 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1885 $this->mPage
->$fname = $fvalue;
1887 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1892 * Use PHP's magic __call handler to transform instance calls to
1893 * WikiPage functions for backwards compatibility.
1895 * @param $fname String Name of called method
1896 * @param $args Array Arguments to the method
1899 public function __call( $fname, $args ) {
1900 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1901 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1902 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1904 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1907 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1910 * @param $limit array
1911 * @param $expiry array
1912 * @param $cascade bool
1913 * @param $reason string
1917 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade, $reason, User
$user ) {
1918 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
1922 * @param $limit array
1923 * @param $reason string
1924 * @param $cascade int
1925 * @param $expiry array
1928 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1929 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
1933 * @param $reason string
1934 * @param $suppress bool
1936 * @param $commit bool
1937 * @param $error string
1940 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1941 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
1949 * @param $resultDetails
1953 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
1954 $user = is_null( $user ) ?
$this->getContext()->getUser() : $user;
1955 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
1962 * @param $resultDetails
1963 * @param $guser User
1966 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
1967 $guser = is_null( $guser ) ?
$this->getContext()->getUser() : $guser;
1968 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
1972 * @param $hasHistory bool
1975 public function generateReason( &$hasHistory ) {
1976 $title = $this->mPage
->getTitle();
1977 $handler = ContentHandler
::getForTitle( $title );
1978 return $handler->getAutoDeleteReason( $title, $hasHistory );
1981 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
1986 public static function selectFields() {
1987 return WikiPage
::selectFields();
1991 * @param $title Title
1993 public static function onArticleCreate( $title ) {
1994 WikiPage
::onArticleCreate( $title );
1998 * @param $title Title
2000 public static function onArticleDelete( $title ) {
2001 WikiPage
::onArticleDelete( $title );
2005 * @param $title Title
2007 public static function onArticleEdit( $title ) {
2008 WikiPage
::onArticleEdit( $title );
2016 * @deprecated since 1.WD, use ContentHandler::getAutosummary() instead
2018 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2019 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );